import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { RemoveTableService } from '../../../../public/serve/remove-table/remove-table.service';
import { HintsService } from '../../../../public/serve/hints/hints.service';
import { internal } from '../../../internal.data';
import { Service } from 'app/server/server';
import { CudTableService } from 'app/public/serve/cud-table/cud-table.service';
declare var $:any;
@Component({
  selector: 'app-time-attribute-edit',
  templateUrl: './time-attribute-edit.component.html',
  styleUrls: ['./time-attribute-edit.component.css']
})
export class TimeAttributeEditComponent implements OnInit {
  details = {
    metaId : '',
    metaName: ''
  };
  @Output() onSubmit = new EventEmitter<void>();
  constructor(
    public request: CudTableService,
    public removeTableService: RemoveTableService,
    private hintsService: HintsService,
    private server: Service,
  ) { }

  ngOnInit() {
  }

  /**
   * 详情
   * @param info
   */
  _details(info: any){
    this.details.metaId = info.metaId;
    this.details.metaName = info.metaName;
  }

  /**
   * 编辑保存
   */
  _onSubmit(info){
    info.token = internal.retrieval.token;
    info.createBy = this.server.getuserName();
    this.request
    .postRequest(this.server.baseUrl + "Service/IdxProduct/updateProductTimeMeta",info)
    .then((res: any)=>{
     
      if(res.result_code === '0000'){
        this.onSubmit.emit();
        $('#internalContents').find("span[data-id='"+info.metaId+"']").attr("data-indexing-name",'时间属性/'+info.metaName);
      }
      $("#timeAttributeEdit").modal("hide");
      this.hintsService.messages(res.message,res.result_code);
      return;
    })
    .catch(err=>{
      this.hintsService.messages("error","error");
      this._editInit();
      return;
    });
  }

  /**
   * 初始化
   */
  private _editInit(){
    $("#edit").modal("hide");
    this.onSubmit.emit();
  }

}
